package com.example.yunxiappbackend.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.yunxiappbackend.pojo.Fenxi;
import com.example.yunxiappbackend.service.FenxiService;
import com.example.yunxiappbackend.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/fenxi")
public class FenxiController {
    @Autowired
    FenxiService fenxiService;

    @PostMapping
    public Result<String> save(@RequestBody Fenxi fenxi){
        fenxiService.save(fenxi);
        return Result.success("保存成功");
    }
    @GetMapping("/{id}")
    public Result<Fenxi> getOne(@PathVariable String id){
        Fenxi one = fenxiService.getById(id);
        return Result.success(one);
    }
    @GetMapping
    public Result<List<Fenxi>> get(String _class){
        System.out.println("_class="+_class);
        LambdaQueryWrapper<Fenxi> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(Fenxi::getFenxiClass,_class);
        List<Fenxi> list = fenxiService.list(queryWrapper);
        return Result.success(list);
    }
    @DeleteMapping("/{id}")
    public Result<String> delete(@PathVariable String id){
        fenxiService.removeById(id);
        return Result.success("删除成功");
    }
}
